--
-- 
--               Copyright [2007] [Sunny Liu]
--
--   Licensed under the Apache License, Version 2.0 (the "License");
--   you may not use this file except in compliance with the License.
--   You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--   Unless required by applicable law or agreed to in writing, software
--   distributed under the License is distributed on an "AS IS" BASIS,
--   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--   See the License for the specific language governing permissions and
--   limitations under the License.
--
<#list entities as entity>

CREATE TABLE ${entity.tableName}
(
<#list entity.attributes as attribute>
<#if attribute.usedInSql >
${attribute.columnName} ${attribute.sqlType} <#if attribute.allowNull >NULL<#else>NOT NULL</#if>,	
</#if>
</#list>
<#list entity.attributes as attribute>
<#if attribute.foreignKey >
constraint fk_${entity.uniqueId} Foreign Key (${attribute.columnName}) references ${attribute.foreignKeyTableName} (${attribute.foreignKeyColumnName}),	
</#if>
</#list>
<#if entity.hasPrimaryKey >
constraint pk_${entity.tableName} PRIMARY KEY (<#list entity.primaryKeyColumnNames as col>${col}<#if col_has_next>, </#if></#list>)
</#if>
)
<#if appConfig.dbType=="mssql" || appConfig.dbType=="sybase">
GO
<#else>
;
</#if>
</#list>